/*
 * @Author: fhw
 * @Date: 2022-07-18 10:30:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-02-04 22:38:21
 * @Description:
 */

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { ArrayNotEmpty, IsArray, IsDefined, IsEnum, IsInt, IsNotEmpty, IsString } from 'class-validator'
import { IdDto } from 'src/common/dto/dto'
import { FindOperator } from 'typeorm'

export class ArticlePageDto {
  public readonly id?: number
  public date?: FindOperator<string>
  @ApiPropertyOptional({
    type: Number,
    name: 'userId',
    description: '用户id',
  })
  public readonly userId?: number
  @ApiPropertyOptional({
    type: String,
    name: 'title',
    description: '标题',
  })
  public readonly title?: FindOperator<string>
  @ApiPropertyOptional({
    type: String,
    name: 'tags',
    description: '标签',
  })
  public tags?: FindOperator<string>
  @ApiPropertyOptional({
    type: String,
    name: 'categories',
    description: '分类',
  })
  public categories?: FindOperator<string>
  @ApiPropertyOptional({
    type: String,
    name: 'status',
    description: '0:保存草稿，1:发布，2:删除',
  })
  public readonly status?: string
  @ApiPropertyOptional({
    type: String,
    name: 'createTimeStart',
    description: '创建开始时间',
  })
  public readonly createTimeStart?: string
  @ApiPropertyOptional({
    type: String,
    name: 'createTimeEnd',
    description: '创建结束时间',
  })
  public readonly createTimeEnd?: string
  @ApiPropertyOptional({
    type: String,
    name: 'pageSize',
    description: 'pageSize',
  })
  public pageSize?: number
  @ApiPropertyOptional({
    type: String,
    name: 'pageNum',
    description: 'pageNum',
  })
  public pageNum?: number
}
export class ArticleInfoDto extends IdDto {
  @ApiPropertyOptional({
    type: String,
    name: 'categories',
    description: '分类',
  })
  public readonly categories?: string
  @ApiPropertyOptional({
    type: String,
    name: 'title',
    description: '文章标题',
  })
  public readonly title?: string
}
// 更新点赞传输数据
export class UpdateArticleThumbsUpDto extends IdDto {
  @IsNotEmpty({ message: 'id不能为空' })
  @IsDefined()
  @ApiProperty({
    type: Number,
    name: 'id',
    description: 'id',
  })
  public readonly id: number
}
// 创建更新文章数据
export class CreateUpdateArticleDto extends IdDto {
  @ApiPropertyOptional({
    type: Number,
    name: 'id',
    description: 'id',
  })
  public readonly id: number

  @IsString({ message: '标题不是String类型' })
  @IsNotEmpty({ message: '标题不能为空' })
  @ApiProperty({
    type: String,
    name: 'title',
    description: '标题',
  })
  public readonly title: string

  @ApiPropertyOptional({
    type: String,
    name: 'content',
    description: '文章内容',
  })
  public readonly content: string

  @ApiPropertyOptional({
    type: Array,
    name: 'tags',
    description: '标签',
  })
  public tags: string[]

  @ApiPropertyOptional({
    type: String,
    name: 'excerpt',
    description: '摘要',
  })
  public readonly excerpt: string

  @ApiPropertyOptional({
    type: Array,
    name: 'categories',
    description: '分类',
  })
  public categories: string[]
  @ApiPropertyOptional({
    type: String,
    name: 'photos',
    description: '图片地址',
  })
  public readonly photos: string
  @IsEnum([0, 1, 2], { message: '只能传入0:保存草稿，1:发布，2:删除' }) //枚举
  @ApiProperty({
    type: String,
    name: 'status',
    description: '0:保存草稿，1:发布，2:删除',
  })
  public readonly status: string
  @ApiPropertyOptional({
    type: Number,
    name: 'userId',
    description: '用户id',
  })
  public readonly userId: number
}
